﻿using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using DistributedCacheEntryOptions = Microsoft.Extensions.Caching.Distributed.DistributedCacheEntryOptions;

namespace Xms.Abp.Caching;

public interface IKeyValueCache<TCacheItem>
{
    Task<bool> KeyExistsAsync(string key, CancellationToken cancellationToken = default);

    Task<DistributedCacheEntryOptions> GetExpirationFromCache(string key, CancellationToken cancellationToken = default);

    Task SetAbsoluteAsync(string key, TCacheItem value, DateTimeOffset expiration, bool? hideErrors = null, bool considerUow = false, CancellationToken cancellationToken = default);

    Task SetSlidingAsync(string key, TCacheItem value, TimeSpan expiration, bool? hideErrors = null, bool considerUow = false, CancellationToken cancellationToken = default);

    Task SetAsync(string key, TCacheItem value, DateTimeOffset absoluteExpiration, TimeSpan slidingExpiration, bool? hideErrors = null, bool considerUow = false, CancellationToken cancellationToken = default);

    Task UpdateAsync(string key, TCacheItem value, bool? hideErrors = null, bool considerUow = false, CancellationToken cancellationToken = default);

    Task<KeyValuePair<string, TCacheItem>[]> GetManyAsync(
        IEnumerable<string> keys,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task<TCacheItem> GetAsync(
        [NotNull] string key,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task<TCacheItem> GetOrAddAsync(
        [NotNull] string key,
        Func<Task<TCacheItem>> factory,
        Func<DistributedCacheEntryOptions> optionsFactory = null,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task<KeyValuePair<string, TCacheItem>[]> GetOrAddManyAsync(
        IEnumerable<string> keys,
        Func<IEnumerable<string>, Task<List<KeyValuePair<string, TCacheItem>>>> factory,
        Func<DistributedCacheEntryOptions> optionsFactory = null,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task SetAsync(
        [NotNull] string key,
        [NotNull] TCacheItem value,
        [CanBeNull] DistributedCacheEntryOptions options = null,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task SetManyAsync(
        IEnumerable<KeyValuePair<string, TCacheItem>> items,
        DistributedCacheEntryOptions options = null,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task RefreshAsync(
        string key,
        bool? hideErrors = null,
        CancellationToken cancellationToken = default
    );

    Task RefreshManyAsync(
        IEnumerable<string> keys,
        bool? hideErrors = null,
        CancellationToken cancellationToken = default);

    Task RemoveAsync(
        string key,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );

    Task RemoveManyAsync(
        IEnumerable<string> keys,
        bool? hideErrors = null,
        bool considerUow = false,
        CancellationToken cancellationToken = default
    );
}

//public interface IKeyValueDistributedCache<T, TOptions> : IKeyValueDistributedCache<T>
//    where T : class
//    where TOptions : XmsCacheOptions
//{
//}
